<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>JQuery easyui demo</title>
	
    <link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.1/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.1/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.1/themes/color.css">
    <link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.1/demo/demo.css">
	<script type="text/javascript" src="jquery-easyui-1.4.1/jquery.min.js"></script>
    <script type="text/javascript" src="jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
    <!-- <div style="height: 70px; width: 100%;">
    	<form id="ff" method="post">   
    <div style="float: left; padding:20px 0 0 20px; ">   
        <label for="name">用户名:</label>   
        <input class="easyui-validatebox" type="text" name="name"  />   
    </div>   
    <div style="float: left;padding:20px 0 0 20px;">   
        <label for="email">邮箱:</label>   
        <input class="easyui-validatebox" type="text" name="email" data-options="validType:'email'" />   
    </div>  
    <div style="float: left;padding:20px 0 0 20px;">   
        <input class="easyui-validatebox" type="button" value="查询" />   
    </div> 
</form>  

    	
    </div> -->
    <table id="provider_dg"  class="easyui-datagrid" style="height: 470px;"
            url="Provider/findAll.do"
            toolbar="#toolbar" pagination="true"
            rownumbers="true" fitColumns="true" singleSelect="true"
            data-options="fit:false,border:false,pageSize:5,pageList:[5,10,15,20]" >
        <thead>
            <tr>
            	<th field="providerNo" width="50">供应商编号</th>
                <th field="provider" width="50">供应商名称</th>
                <th field="paddress" width="50">供应商地址</th>
                <th field="plinkman" width="50">联系人</th>
                <th field="pemail" width="50">供应商邮箱</th>
                <th field="pphone" width="50">供应商电话</th>
            </tr>
        </thead>
    </table>
    <div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newProvider()">新增</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editProvider()">编辑</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyProvider()">删除</a>
    </div>
    
    <div id="providerdlg" class="easyui-dialog"  style="padding:10px 20px"
            closed="true" buttons="#dlg-buttons">
        <div class="ftitle">详细信息</div>
        <form id="fm" method="post" novalidate>
            
            <div class="fitem">
                <label>供应商名称:</label>
                <input name="provider" class="easyui-textbox">
            </div>
            <div class="fitem">
                <label>供应商地址:</label>
                <input name="paddress" class="easyui-textbox">
            </div>
            <div class="fitem">
                <label>联系人:</label>
                <input name="plinkman" class="easyui-textbox"">
            </div>
            <div class="fitem">
                <label>供应商邮箱:</label>
                <input name="pemail" class="easyui-textbox">
            </div>
            <div class="fitem">
                <label>供应商电话:</label>
                <input name="pphone" class="easyui-textbox">
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveProvider()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
    </div>
    <script type="text/javascript">
    
  //重新设置easy UI的时间格式
	$.fn.datebox.defaults.formatter=function(date){
		var y=date.getFullYear();
		var m=date.getMonth()+1;
		var d=date.getDate();
		return y+'/'+m+"/"+d;
	}
	$.fn.datebox.defaults.parser=function(date){
		if(date){
			return new Date(date);
			
		}else{
			return new Date();
		}
		
	}
    
    
        var url;
        //新增
        function newProvider(){
            $('#providerdlg').dialog('open').dialog('setTitle','新增');
            $('#fm').form('clear');//清除表单数据
            url = 'Provider/add.do';//新增调用的网址
        }
        //编辑
        function editProvider(){
            var row = $('#provider_dg').datagrid('getSelected');
            if (row){
                $('#providerdlg').dialog('open').dialog('setTitle','编辑');
                $('#fm').form('clear');//清除表单数据
                $('#fm').form('load',row);
                url = 'Provider/update.do?providerNo='+row.providerNo;
            }
        }
        //保存
        function saveProvider(){
            $('#fm').form('submit',{
                url: url,
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(result){
                    var result = eval('('+result+')');
                    if (result.errorMsg){
                        $.messager.show({
                            title: 'Error',
                            msg: result.errorMsg
                        });
                    } else {
                        $('#providerdlg').dialog('close');        // close the dialog
                        $('#provider_dg').datagrid('reload');    // reload the user data
                    }
                }
            });
        }
        //删除
        function destroyProvider(){
            var row = $('#provider_dg').datagrid('getSelected');
            if (row){
                $.messager.confirm('Confirm','确定要删除吗?',function(r){
                    if (r){
                        $.post('Provider/delete.do',{providerNo:row.providerNo},function(result){
                            if (result.success){
                                $('#provider_dg').datagrid('reload');    // reload the user data
                            } else {
                                $.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
       


       
    </script>
    <style type="text/css">
        #fm{
            margin:0;
            padding:10px 30px;
        }
        .ftitle{
            font-size:14px;
            font-weight:bold;
            padding:5px 0;
            margin-bottom:10px;
            border-bottom:1px solid #ccc;
        }
        .fitem{
            margin-bottom:5px;
        }
        .fitem label{
            display:inline-block;
            width:80px;
        }
        .fitem input{
            width:160px;
        }
    </style>
</body>
</html>